package com.jt.tenant.activity;


import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.jt.tenant.R;
import com.jt.tenant.adapter.InsCheckSelectAdapter;
import com.jt.tenant.app.JTApplication;
import com.jt.tenant.conn.GetInsSelect;
import com.jt.tenant.dialog.TipDialog;
import com.jt.tenant.widget.MyListView;
import com.jt.tenant.widget.Tools;
import com.zcx.helper.http.AsyCallBack;
//import com.jt.tenant.adapter.InsCheckSelectAdapter;
//import com.jt.tenant.conn.SetNewInsOrder;
//import com.jt.tenant.dialog.InsCancelDialog;
//import com.jt.tenant.dialog.ResultDialog;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;


public class InsCheckSelectActivity extends JTActivity implements View.OnClickListener,Serializable {

    private TextView title,commit,next;//标题，标题栏右侧按钮,下一步

    private View footView;

    private LinearLayout call;

    private MyListView insLists;//总价，起期，止期

    private List<GetInsSelect.InsItem> mLists = new ArrayList<>();

    private InsCheckSelectAdapter mAdapter;

    private TextView total_price,start_time,end_time;

    private GetInsSelect getInsSelect = new GetInsSelect(new AsyCallBack<GetInsSelect.Info>(){

        @Override
        public void onSuccess(String toast, int type, GetInsSelect.Info info) throws Exception {

            super.onSuccess(toast, type, info);

            if(info.msg.equals("000")){

                mLists.clear();

                mLists.addAll(info.insList);

                mAdapter.notifyDataSetChanged();

            }
        }
    });


    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_ins_select_check);

        footView = View.inflate(context, R.layout.foor_ins_check, null);

        JTApplication.ScaleScreenHelper.loadView((ViewGroup) footView);

        initview();


    }

    private void initview(){

        (title = (TextView) findViewById(R.id.tv_title_name)).setText("险种详情");

        (commit = (TextView) findViewById(R.id.commit)).setText("取消查询");

        commit.setOnClickListener(this);

        (next = (TextView) findViewById(R.id.tv_ins_check_select_next)).setOnClickListener(this);

        (call = (LinearLayout) findViewById(R.id.lin_ins_call)).setOnClickListener(this);

        total_price = (TextView)footView.findViewById(R.id.tv_ins_check_price);

        start_time = (TextView)footView.findViewById(R.id.tv_ins_check_starttime);

        end_time = (TextView)footView.findViewById(R.id.tv_ins_check_endtime);

        insLists = (MyListView)findViewById(R.id.lv_ins_check_select);

        insLists.addFooterView(footView);

        mAdapter = new InsCheckSelectAdapter(InsCheckSelectActivity.this,mLists);

        insLists.setAdapter(mAdapter);

        getInsSelect.execute(this);

    }



    @Override
    public void onClick(View view) {
        super.onClick(view);

        switch (view.getId()) {

            case R.id.lin_ins_call:

                Tools.Call(this,"4006115616");

                break;

            case R.id.tv_ins_check_select_next:

//                TipDialog tipDialog = new TipDialog(context);
//
//                tipDialog.setType(0);
//
//                tipDialog.setTip("稍后将由专人为您审核、报价，请耐心等待。");
//
//                tipDialog.show();

                startActivity(new Intent(this,InsQuoteActivity.class));

                break;

            case R.id.commit:

                TipDialog cancelDialog = new TipDialog(context);

                cancelDialog.setTip("确定取消报价查询？如果取消将丢失已填写数据");

                cancelDialog.setType(5);

                cancelDialog.show();

                break;
        }
    }

    @Override
    public void onBack(View v) {

        super.onBack(v);

        startActivity(new Intent(InsCheckSelectActivity.this,MainActivity.class));

    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {

        if (keyCode == KeyEvent.KEYCODE_BACK) {

            startActivity(new Intent(InsCheckSelectActivity.this,MainActivity.class));

        }

        return true;
    }
}
